<?
require 'global.php';
include(ROOT."common/mail_send.php");

// product id. 产品id
$id=0; if(isset($_GET["id"]))if(is_numeric($_GET["id"]))$id=$_GET["id"];
$url="feedback";

$action='you guess';
if(isset($_POST["action"]) && $_POST["action"]!="") $action=clean($_POST["action"]);
if($action=='add'){
	$key='you guess'; // safety key 安全码, 过滤非法提交
	if(isset($_POST["key"]) && $_POST["key"]!="") $key=clean($_POST["key"]);
	if($key != md5('ecomgear'.date('Ymd'))){ yell(WEB_INVALID_ACCESS,'./'); exit; }

	$arr=array(
		'email'=>clean($_POST['email']),
		'name'=>clean($_POST['name']),
		'content'=>clean($_POST['content']),
	);
	if(isset($_POST["phone"]) && $_POST["phone"]!="") $arr['phone']=clean($_POST["phone"]);
	if($feedback->insert($arr)){
		// 发电邮
		$subject=WEB_GOT_FEEDBACK.' - '.$arr['name'].' - '.SITE_URL;
		$body='Hi, '.WEB_GOT_FEEDBACK.'--<br />';
		$body.='<br />'.WEB_NAME.': '.$arr['name'].'<br />'.WEB_EMAIL.': '.$arr['email'];
		if(isset($arr['phone']))$body.='<br />'.WEB_PHONE.': '.$arr['phone'];
		$body.='<br />'.WEB_CONTENT.': '.$arr['content'];
		$body.='<br /><br />'.date('Y-m-d H:i:s').'<br />'.SITE_URL;
		$body='<!doctype html><html>
			<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
			<title>'.$subject.'</title></head>
			<body>'.$body.'</body></html>';

		$email_admin_txt=DAILY_SALES_ORDER_RECIPIENT_EMAILS;
		$tem_array=explode(',', $email_admin_txt);
		$email_admin=array();
		foreach($tem_array as $val) $email_admin[]=trim($val);
		$arrmail=array(
			'to'=>$email_admin,
			'subject'=>$subject,
			'body'=>$body,
			'host'=>EMAIL_HOST,
			'account'=>EMAIL_ACCOUNT,
			'password'=>EMAIL_PASSWORD,
			'port'=>EMAIL_PORT,
			'name'=>EMAIL_NAME,
			'ssl'=>EMAIL_SSL,
		);
		@mail_send($arrmail);
		yell(WEB_FEEDBACK_OK, './'); exit; 
	}
	else { yell(WEB_FEEDBACK_FAILED, 'feedback.php'); }
}

$tem = $about->get_rows(32,'','','seq_no');
$arr_cate=array();
foreach($tem as $val) $arr_cate[$val['id']]=$val;

// SEO 设置 seo tags
$title=WEB_FEEDBACK.' - '.$config['SITE_TITLE_'.LANG];
$kwd=$title;
$dpn=$kwd;

// ad 广告
$tem=$ad->get_rows(16,'category_id',1);
shuffle($tem);
$ad_right=$tem[0];

// view 加载视图
require VIEW.$url.'.php';


// end of file
